package com.geping.etl.common.controller;

import com.geping.etl.common.entity.Report_Info;
import com.geping.etl.common.service.GroupService;
import com.geping.etl.common.service.Report_InfoService;
import com.geping.etl.common.vo.ResponseVo;
import com.geping.etl.utils.EnvUitl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author xuanhao.ji
 * @date 2022/2/9
 */

@Slf4j
@Controller
public class GroupController {

    @Autowired
    private GroupService groupService;

    @Autowired
    private Report_InfoService report_infoService;

    @ResponseBody
    @RequestMapping("/addGroupInfo")
    public ResponseVo addGroupInfo(String code, String info, String subjectId) {
        log.info("addGroupInfo start, code = {}, data = {}, subjectId = {}", code, info, subjectId);
        ResponseVo responseVo = groupService.dealWithInfo(code, info, subjectId);
        return responseVo;
    }

    @RequestMapping("/findRecordBySubject")
    public ModelAndView findRecordBySubject(String subjectId) {
        log.info("start refresh form data by subjectId = {}", subjectId);
        ModelAndView mv = new ModelAndView();
        try {
            if(subjectId == null || subjectId.equals("")) {
                subjectId = "1";
            }
            String east2Huachen = EnvUitl.props.getProperty("east2.huachen");
            List<Report_Info> roleList = report_infoService.getReportBySubjectId(subjectId,east2Huachen);
            mv.addObject("list", roleList);
            mv.addObject("subjectId", subjectId);
            mv.setViewName("common/sys_audit_authority");
        }catch (Exception e) {
            log.error("method findRecordBySubject error -> {}",e);
        }
        return mv;
    }
}
